<?php
if (!defined('DEDEINC')) exit('dedebiz');
function jjGetTypefenlei($str)
{
    global $dsql;
    $arr = $dsql->GetOne("select * from #@__arctype where typename = '$str' and reid = '17' ");
    return GetTypeDeurl($arr['id']);
}

//  作者：覃小华  获取课程文章数
function jjKeCount($tid)
{
    global $dsql;
    $arr = $dsql->GetOne("select count(id) as dd  from #@__arctiny where typeid = '$tid' and arcrank > -2");
    if (empty($arr['dd']))
    {
        $arr['dd'] = "O";
    }
    return $arr['dd'];
}

//  作者：覃小华  获取后台栏目的分类属性
function getTypeShuxing($v = '')
{
    global $dsql;
    $sql = "select id,typename from #@__arctype where reid = '17'";
    $dsql->Execute('me', $sql);
    $jg = '';
    while ($arr = $dsql->GetArray('me'))
    {
        if ($v == $arr['id'])
        {
            $f = ' checked="1" ';
        }
        else
        {
            $f = '';
        }
        $jg .= '<label style="margin-right:10px;"><input type="radio" name="fenlei" value="' . $arr['id'] . '" class="np"  ' . $f . ' />' . $arr['typename'] . '</label>';
    }
    return $jg;
}

// 作者：覃小华  获取栏目信息
function jjGetTypename($tid)
{
    global $dsql;
    $trr = $dsql->GetOne("select typename from #@__arctype where id = '$tid'");
    if (empty($trr['typename']))
    {
        $trr['typename'] = '';
    }
    return $trr['typename'];
}

function GetTypeDeurl($tid)
{
    global $dsql;
    $arr = $dsql->GetOne("select * from #@__arctype where id = '$tid'");
    $jg  = GetOneTypeUrlA($arr);
    return $jg;
}

function JJGetTypeList($page, $pagesize)
{
    global $dsql, $cfg_basehost, $cfg_dazhe, $cfg_zhekou, $cfg_dqtime;
    $s         = ($page - 1) * $pagesize;
    $sql       = "select t.id,t.bigpic,t.typename,t.kcyj,SUM(a.click) as click,t.price,t.kcyj,count(a.id) as dd  from #@__arctype t left join #@__archives a on t.id = a.typeid 
     where t.reid = '18' group by t.id order by t.id desc limit $s,$pagesize ";
    $time      = time();
    $timestamp = strtotime($cfg_dqtime);
    //var_dump($sql);
    $dsql->Execute('me', $sql);
    $jg = '';
    while ($arr = $dsql->GetArray('me'))
    {
        $brr = $dsql->GetOne("select count(a.id) as num from #@__member_stow a left join #@__arctiny b on a.aid = b.id where b.typeid = '" . $arr['id'] . "' ");

        if (empty($arr['bigpic']))
        {
            $bigpic = '/images/yxw-sc-bg.gif';
        }
        else
        {
            $bigpic = $cfg_basehost . $arr['bigpic'];
        }
        if (empty($arr['click']))
        {
            $arr['click'] = '0';
        }
        if ($arr['click'] > 10000)
        {
            $arr['click'] = number_format($arr['click'] / 10000, 1) . '万';
        }

        if (empty($arr['num']))
        {
            $arr['num'] = '0';
        }

        if ($arr['num'] > 10000)
        {
            $arr['num'] = number_format($arr['num'] / 10000, 1) . '万';
        }
        $oprice = $arr['price'];
        if (!empty($oprice))
        {
            if ($cfg_dazhe == 'Y' && $timestamp > $time)
            {
                $dzprice   = $oprice / 100 * $cfg_zhekou;
                $pricehtml = "<span class=\"price\"><i>￥</i>{$dzprice} <small>￥{$oprice}</small></span>";
            }
            else
            {
                $pricehtml = "<span class=\"price\"><i>￥</i>{$oprice}</span>";
            }
        }
        else
        {
            $pricehtml = "<span class=\"ke-mianfei\">免费</span>";
        }
        $jg .= '<li class="content_item">
<a href="' . GetTypeDeurl($arr['id']) . '" class="link" title="' . $arr['typename'] . '" target="_blank">
<img src="' . $bigpic . '">
<div class="main_title_box">
<div class="main_title">' . $arr['typename'] . '</div>
<div class="sub_title">
' . $pricehtml . '
<span class="item_right fr">' . $arr['click'] . '次学习</span>
</div>
</div>
</a>
</li>';
    }
    return $jg;
}


function JJgetCliak($tid)
{
    global $dsql;
    $arr = $dsql->GetOne("select sum(click) as click from #@__archives where typeid = '$tid'");
    if (empty($arr['click']))
    {
        $arr['click'] = '0';
    }
    if ($arr['click'] > 10000)
    {
        $arr['click'] = number_format($arr['click'] / 10000, 1) . '万';
    }
    return $arr['click'];
}


function mstrup($now)
{
    global $cfg_basehost;
    $mst = str_replace("\"/static/allimg/", "\"{$cfg_basehost}/static/allimg/", $now);
    return $mst;
}

function mstrone($noo)
{
    global $cfg_basehost;
    if (strstr($noo, "//"))
    {
        $mso = $noo;
    }
    else
    {
        $mso = $cfg_basehost . $noo;
    }
    return $mso;
}


//作者：覃小华  文章点击数过万之后的显示效果
function click_round_number($number, $min_value = 10000, $decimal = 1)
{
    if ($number < $min_value)
    {
        return $number;
    }
    $alphabets = array(100000000 => '亿', 10000 => '万');
    foreach ($alphabets as $key => $value)
    {
        if ($number >= $key)
        {
            return round($number / $key, $decimal) . '' . $value;
        }
    }
}

function JJseoTitle($tid)
{
    global $dsql;
    $arr = $dsql->GetOne("select seotitle from #@__arctype where id = '$tid'");
    return $arr['seotitle'];
}

function JJarctype($aid)
{
    global $dsql;
    $arr = $dsql->GetOne("select typeid from #@__archives where id = '$aid'");
    return $arr['typeid'];
}

// 作者：覃小华  2020.4.14
function JJseourl($tid)
{
    global $dsql;
    $arr = $dsql->GetOne("select seourl from #@__arctype where id = '$tid'");
    return $arr['seourl'];
}


// 作者：覃小华  2020.4.14 文章静态点击率
function xhclick($tid)
{
    global $dsql;
    $arr = $dsql->GetOne("select click from #@__archives where id = '$tid'");
    return $arr['click'];
}


// 作者：覃小华  获取课程封面图
function jjbigpic($tid)
{
    global $dsql;
    $trr = $dsql->GetOne("select bigpic from #@__arctype where id = '$tid'");
    return $trr['bigpic'];
}


//作者：覃小华 2018年11月5日
function JJtypeurl($tid)
{
    global $dsql;
    $arr = $dsql->GetOne("select * from #@__arctype where id = '$tid'");
    $jg  = GetOneTypeUrlA($arr);
    return $jg;
}


//作者：覃小华 获取文章列表
function JJGetTYpeARcLIST($tid)
{
    global $dsql;
    $sql = "select a.id,a.title,b.spmm,a.source from #@__archives a left join #@__addonvideo b on a.id = b.aid where a.typeid = '$tid' order by a.pubdate desc";
    $dsql->Execute('me', $sql);
    $jg = '';
    while ($arr = $dsql->GetArray('me'))
    {
        $jg .= '<li><a href="' . aaurl($arr['id']) . '" class="jjdd' . $arr['id'] . '">' . $arr['spmm'] . '.' . $arr['title'] . '</a></li>';
    }
    return $jg;
}


// 作者：覃小华 2019年2月24日16:20:06
function GetTypeDeurlformarr($arr)
{
    $jg = GetOneTypeUrlA($arr);
    return $jg;
}

function str_split_unicode($str, $l = 0)
{
    if ($l > 0)
    {
        $ret = array();
        $len = mb_strlen($str, "UTF-8");
        for ($i = 0; $i < $len; $i += $l)
        {
            $ret[] = mb_substr($str, $i, $l, "UTF-8");
        }
        return $ret;
    }
    return preg_split("//u", $str, -1, PREG_SPLIT_NO_EMPTY);
}


// 作者：覃小华  文章发布多少时间前
function tranTime($time)
{
    ini_set('date.timezone', 'Asia/Shanghai');
    $day1    = date('Y-m-d', $time);
    $day2    = date("Y-m-d");
    $second1 = strtotime($day1);
    $second2 = strtotime($day2);
    if ($second1 < $second2)
    {
        $tmp     = $second2;
        $second2 = $second1;
        $second1 = $tmp;
    }
    $updays = round(($second1 - $second2) / 86400);
    if ($updays == 0)
    {
        $str = '今天';
    }
    elseif ($updays == 1)
    {
        $str = '昨天';
    }
    elseif ($updays == 2)
    {
        $str = '前天';
    }
    elseif ($updays > 2 && $updays < 8)
    {
        $str = $updays . '天前';
    }
    else
    {
        $str = date('n', $time) . '月' . date('j', $time) . '日';
    }
    return $str;
}


function is_mobile()
{
    if (isset ($_SERVER['HTTP_X_WAP_PROFILE']))
    {
        // 如果有HTTP_X_WAP_PROFILE则一定是移动设备
        return true;
    }
    elseif (isset ($_SERVER['HTTP_USER_AGENT']))
    {
        // 判断手机发送的客户端标志,兼容性有待提高
        $clientkeywords = ['nokia', 'sony', 'ericsson', 'mot', 'samsung', 'htc', 'sgh', 'lg', 'sharp', 'sie-', 'philips', 'panasonic', 'alcatel', 'lenovo', 'iphone', 'xiaomi', 'ipod', 'blackberry', 'meizu', 'android', 'netfront', 'symbian', 'ucweb', 'windowsce', 'palm', 'operamini', 'operamobi', 'openwave', 'nexusone', 'cldc', 'midp', 'wap', 'mobile'];
        // 从HTTP_USER_AGENT中查找手机浏览器的关键字
        if (preg_match("/(" . implode('|', $clientkeywords) . ")/i", strtolower((string)$_SERVER['HTTP_USER_AGENT'])))
        {
            return true;
        }
    }
    // 协议法，因为有可能不准确，放到最后判断
    if (isset ($_SERVER['HTTP_ACCEPT']))
    {
        // 如果只支持wml并且不支持html那一定是移动设备
        // 如果支持wml和html但是wml在html之前则是移动设备
        if ((strpos($_SERVER['HTTP_ACCEPT'], 'vnd.wap.wml') !== false) && (strpos($_SERVER['HTTP_ACCEPT'], 'text/html') === false || (strpos($_SERVER['HTTP_ACCEPT'], 'vnd.wap.wml') < strpos($_SERVER['HTTP_ACCEPT'], 'text/html'))))
        {
            return true;
        }
    }
    return false;
}
